package com.longy.gulimall.product.service.impl;


import com.longy.common.utils.PageUtils;
import com.longy.common.utils.Query;
import com.longy.gulimall.product.entity.AttrEntity;
import com.longy.gulimall.product.service.AttrService;
import com.longy.gulimall.product.vo.AttrGroupRelationVo;
import com.longy.gulimall.product.vo.AttrGroupWithAttrsVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.longy.gulimall.product.dao.AttrAttrgroupRelationDao;
import com.longy.gulimall.product.entity.AttrAttrgroupRelationEntity;
import com.longy.gulimall.product.service.AttrAttrgroupRelationService;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupRelationEntity> page = this.page(
                new Query<AttrAttrgroupRelationEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveBatch(List<AttrGroupRelationVo> attrGroupIds) {
        List<AttrAttrgroupRelationEntity> collect = attrGroupIds.stream().map((item -> {
            AttrAttrgroupRelationEntity entity = new AttrAttrgroupRelationEntity();
            BeanUtils.copyProperties(item, entity);
            return entity;
        })).collect(Collectors.toList());


        this.saveBatch(collect);
    }



}